using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Platform.CharacterData
{
    [System.Serializable]
    public class Stat
    {
        public List<float> modifiers = new();
        public List<float> percentageModifiers = new(); // 百分比修正列表

        public float Value
        {
            get
            {
                float finalValue = baseValue;
                modifiers.ForEach(x => finalValue += x);

                // 应用所有百分比修正
                float percentageAdjustment = 1f;
                percentageModifiers.ForEach(x => percentageAdjustment *= x);

                finalValue *= percentageAdjustment;  // 直接乘以最终的百分比修正

                return finalValue;
            }
            set { baseValue = value; }
        }

        [SerializeField]
        private float baseValue;

        public virtual void AddModifier(float modifier)
        {
            modifiers.Add(modifier);
        }

        /// <summary>
        /// 传入小数
        /// </summary>
        /// <param name="modifier"></param>
        public virtual void AddPercentModifier(float modifier)
        {
            percentageModifiers.Add(modifier);
        }

        public virtual void RemoveModifier(int modifier)
        {
            modifiers.Remove(modifier);
        }

        public virtual void RemovePercentModifier(float modifier)
        {
            percentageModifiers.Remove(modifier);
        }

        // 可选：清除所有修饰符
        public void ClearModifiers()
        {
            modifiers.Clear();
        }
    }
}
